import requestWy from "./request-wy";
import requestSph from './request-sph'; //商品汇

/* requestWy.post(
    '/xhr/search/searchAutoComplete.json',
    {
      ['content-type']: 'application/json;charset=UTF-8',
    },
    {
      params: {
        keywordPrefix: keyword,
      },
    }
 */

export default {
    // 获取热门搜索数据
    getPopularList() {
        return requestWy.get('/xhr/search/init.json')
    },
    // 输入时展示的数据
    getNavigationList(keywordPrefix) {
        return requestWy.post('/xhr/search/searchAutoComplete.json', {
            ['content-type']: 'application/json;charset=UTF-8',
        }, {
            params: {
                keywordPrefix
            }
        })
    },
    // 展示的商品数据
    getGoodsList({keyword,categoryId=0,upperPrice = -1,floorPrice = -1,descSorted = 1}) {
        
      descSorted = descSorted == 1 ? false : true

        let timestamp = Date.now()
        return requestWy({
            url: `/xhr/search/search.json?__timestamp=${timestamp}&needPopWindow=true&searchWordSource=7&stillSearch=false&_stat_search=autoComplete&itemId=0&size=40&upperPrice=${upperPrice}&floorPrice=${floorPrice}&matchType=0&categoryId=${categoryId}&descSorted=${descSorted}&sortType=0&keyword=${keyword}`,
            method:'post',
            headers:{
                'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'
            }
        })
    }

}
